<?php


namespace App\Extensions\Grid\Displayers;


use Encore\Admin\Grid\Displayers\AbstractDisplayer;

class LayerShow extends AbstractDisplayer
{
    public function display($callback = '', $title = '详情', $width = '1000', $height = '800')
    {
        if ($callback instanceof \Closure) {
            $callback = $callback->bindTo($this->row);
            $href = call_user_func_array($callback, [$this->row]);
        } else {
            $href = $callback ?: $this->value;
        }
        if (!$href) {
            return $this->value;
        }
        if ($width) {
            return $this->layerShow($this->value, $title, $href, $width, $height);
        }
        return $this->layerFull($this->value, $title, $href);
    }

    private function layerShow($value, $title, $href, $width, $height)
    {
        return <<<EOT
  <a href="javascript:;" onclick="layer_show('{$title}','{$href}','{$width}','{$height}')">{$value}</a>
EOT;
    }

    private function layerFull($value, $title, $href)
    {
        return <<<EOT
  <a href="javascript:;" onclick="layer_full('{$title}','{$href}')">{$value}</a>
EOT;
    }

}
